using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class forums_controls_threads_NewThreadPage : Controls.DataManagerForumControl
{
    protected override void ItemChanged()
    {
        if (CurrentForum != null &&
            Helpers.ForumSecurityHelper.CurrentUserCanViewForum(CurrentForum))
        {
            mviewThread.SetActiveView(viewThread);
            Header1.SetList(CurrentForum, false);
            Header1.SetItem("New Thread");
        }
        else
        {
            mviewThread.SetActiveView(viewNoForum);
            Header1.SetItem("Forum not found");
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        DAL.User myUser = Managers.UserLoginManager.CurrentUser;
        if (myUser != null)
        {
            if (!Page.IsPostBack)
            {
                CurrentForum = GetItemFromQueryString();
            }
        }
        else
        {
            Response.Redirect("~/forums/default.aspx");
        }

        if (CurrentForum != null)
        {
            Page.Title = "FSTDT Forums: " + Helpers.StringHelper.SafeFormat("New Thread in {0}", CurrentForum.Name);
        }
        else
        {
            Page.Title = "FSTDT Forums: " + "Forum not found";
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        DAL.User myUser = Managers.UserLoginManager.CurrentUser;
        if (Page.IsValid && myUser != null)
        {
            DAL.Post myPost = new DAL.Post();
            myPost.Subject = txtSubject.Text;
            myPost.Content = txtPost.Text;
            myPost.User = Managers.UserLoginManager.CurrentUser;
            DAL.Posts.AddWithNewThread(myPost, CurrentForum);

            Response.Redirect(String.Format("~/forums/thread.aspx?t={0}", myPost.Thread.ID));
        }
    }
    protected void btnPreview_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            PreviewPost1.SetPreview(txtSubject.Text, txtPost.Text);
        }
    }
}
